<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="height: auto;">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<title>CSIè¯­é³ ææ¯å§</title>
	<link rel="stylesheet" href="../js/metronic/plugins/bootstrap/css/bootstrap.css">
	<link rel="stylesheet" href="../login/css/font-awesome.min.css">
	<link rel="stylesheet" href="../js/metronic/plugins/ionicons/css/ionicons.min.css">
	<link rel="stylesheet" href="../js/metronic/plugins/adminlte/css/adminlte.css">

</head>

<body style="height: auto;">


	<!--<div id="ORG_ADD_DIV_ID" class="card card-info" style="display:none">  -->
	<div id="POST_ADD_DIV_ID" class="card card-info">
		<input id="regUUID" type="hidden" value=""/>
		<div class="form-horizontal">
			<div class="card-body">
				<div class="form-group">
					<label for="JI_JOB_NAME" class="col-sm-2 control-label">新的密码：</label>
					<div class="col-sm-10">
						<input value="" type="password" name="newPassword" id="newPassword" class="form-control"
						       placeholder="请输入您的新密码" style="width:600px">
					</div>
				</div>
				<div class="form-group">
					<label for="JI_JOB_NAME" class="col-sm-2 control-label">确认密码：</label>
					<div class="col-sm-10">
						<input value="" type="password" name="newPasswordCon" id="newPasswordCon" class="form-control"
						       placeholder="请确认您的新密码" style="width:600px">
					</div>
				</div>
				<div class="form-group">
					<label for="JI_JOB_NAME" class="col-sm-2 control-label">当前密码：</label>
					<div class="col-sm-10">
						<input value="" type="password" name="oldPassword" id="oldPassword" class="form-control"
						       placeholder="请输入您的当前密码" style="width:600px">
					</div>
				</div>
				<!-- /.card-body -->
				<div class="card-footer col-md-3 col-md-offset-4" style="width:100%" align="center">
					<button type="button" id="btn-submit" class="btn btn-info">提交</button>
				</div>
				<div class="card-footer col-md-3 col-md-offset-4" id="tishi"
				     style="text-align: center;color: red;font-size: 15px">

				</div>
				<!-- /.card-footer -->
			</div>
		</div>
	</div>


	<script src="../js/metronic/plugins/jquery/dist/jquery.js"></script>
	<script src="../js/metronic/plugins/jQuery-Storage-API/jquery.storageapi.js"></script>
	<script src="../js/metronic/plugins/jquery.form/jquery.form.min.js"></script>
	<script src="../js/metronic/plugins/jquery/plugins/scrollbar/perfect-scrollbar.jquery.min.js"></script>
	<link href="../js/ligerUI/skins/Aqua/css/ligerui-dialog.css" rel="stylesheet" type="text/css"/>
	<script src="../js/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>

	<script>
		$('#btn-submit').click(function () {
			var newPassword = $("#newPassword").val();
			var newPasswordCon = $("#newPasswordCon").val()
			var oldPassword = $("#oldPassword").val()


			if (typeof (newPassword) == 'undefined' || newPassword.trim() == "") {
				$("#tishi").html("新密码不能为空");
				return;
			}
			if (newPassword.trim().length < 6 || newPassword.trim().length > 20) {
				$("#tishi").html("新密码必须大于6位小于20位");
				return;
			}
			if (typeof (newPasswordCon) == 'undefined' || newPasswordCon.trim() == "") {
				$("#tishi").html("确认密码不能为空");
				return;
			}
			if (newPassword.trim() != newPasswordCon.trim()) {
				$("#tishi").html("新密码与确认密码必须保持一致");
				return;
			}

			if (typeof (oldPassword) == 'undefined' || oldPassword.trim() == "") {
				$("#tishi").html("当前密码不能为空");
				return;
			}

			let editPassword = {
				oldPassword: oldPassword.trim(),
				newPassword: newPassword.trim(),
			}
			$('#btn-submit').unbind('click');
			$.ajax({
				type: "POST",
				url: "/csi/user/api/editPassword",
				async: true,
				data: JSON.stringify(editPassword),
				contentType: 'application/json;charset=UTF-8',
				dataType: "json",
				error: function (XMLHttpRequest, textStatus, text) {
					$.ligerDialog.error(JSON.stringify(text), "出错了，请于管理员联系");
				},
				success: function (result) {
					console.log(result);
					let data;
					try {

						data = checkResultAndGetData(result);
					} catch (error) {
						$.ligerDialog.warn(result.message, "修改失败");
						return;
					}
					$.ligerDialog.success("修改成功");
				}
			});

		});

		// }

		function checkResultAndGetData($result) {
			if ($result.success == false) {
				throw $result;
			}
			return $result.data;
		}
	</script>
</body>
</html>